package cn.shyouchi.wuguanjia.android.ui.home.security.thread.me;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.shyouchi.wuguanjia.android.Global;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseFragment;
import cn.shyouchi.wuguanjia.android.components.storage.UserStorage;
import cn.shyouchi.wuguanjia.android.ui.about.AboutActivity;
import cn.shyouchi.wuguanjia.android.ui.profile.ProfileActivity;
import cn.shyouchi.wuguanjia.android.widget.GlideCircleTransform;
import cn.shyouchi.wuguanjia.android.widget.TopBar;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends BaseFragment {


    @BindView(R.id.topBar)
    TopBar mTopBar;


    UserStorage mUserStorage;
    @BindView(R.id.img_header)
    ImageView mImgHeader;
    @BindView(R.id.tv_person_name)
    TextView mTvPersonName;
    @BindView(R.id.tv_person_phone)
    TextView mTvPersonPhone;
    @BindView(R.id.img_qrcode)
    ImageView mImgQrcode;
    @BindView(R.id.item_person)
    LinearLayout mItemPerson;
    @BindView(R.id.item_salary)
    LinearLayout mItemSalary;
    @BindView(R.id.item_chat)
    LinearLayout mItemChat;
    @BindView(R.id.item_collect)
    LinearLayout mItemCollect;
    @BindView(R.id.item_remind)
    LinearLayout mItemRemind;
    @BindView(R.id.item_version)
    LinearLayout mItemVersion;

    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public void initInjector() {
        mUserStorage = new UserStorage(getContext());
    }

    @Override
    public int initContentView() {
        return R.layout.fragment_me;
    }

    @Override
    public void getBundle(Bundle bundle) {

    }

    @Override
    public void initUI(View view) {
        ButterKnife.bind(this, view);
        showContent(false);
        mTopBar.setTitle("我的");
        loadHead(Global.BASE_URL + mUserStorage.getUserData().getAvatar());
        mTvPersonName.setText(String.format("%s(%s)", mUserStorage.getUserData().getName(), mUserStorage.getUserData().getPermissions_name()));
        mTvPersonPhone.setText(String.format("手机号码：%s", mUserStorage.getUserData().getUsername()));
    }

    @Override
    public void initData() {


    }


//    @OnClick(R.id.btn_exit)
//    public void onClick() {
//        mUserStorage.clear();
//        startActivity(new Intent(getContext(), LoginActivity.class));
//        getActivity().finish();
//    }


    @OnClick({R.id.img_qrcode, R.id.item_person, R.id.item_salary, R.id.item_chat, R.id.item_collect, R.id.item_remind, R.id.item_version})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_qrcode:

                break;
            case R.id.item_person:
                startActivity(new Intent(getContext(), ProfileActivity.class));
                break;
            case R.id.item_salary:

                break;
            case R.id.item_chat:

                break;
            case R.id.item_collect:

                break;
            case R.id.item_remind:
                startActivity(new Intent(getContext(), NotificationSetActivity.class));
                break;
            case R.id.item_version:
                startActivity(new Intent(getContext(), AboutActivity.class));
                break;
        }
    }


    private void loadHead(String path) {
        Glide.with(getContext())
                .load(path)
                .placeholder(R.mipmap.ic_default_header)
                .transform(new GlideCircleTransform(getContext()))
                .into(mImgHeader);
    }

}
